﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Quartz;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace JobService.Api
{
    [Route("/api/job")]
    public class JobController : Controller
    {
        private IScheduler  _scheduler;
        public JobController(IScheduler  scheduler){

            _scheduler = scheduler;
        }
        
        // GET: /<controller>/
        [HttpGet("list")]
        public IActionResult list()
        {
            return Json(new
            {
                total = 1000,
                items = new Object[] {
                   new {
                       id=1,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=2,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=3,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=4,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=5,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=6,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=7,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=8,
                       timestamp = DateTime.Now,
                       author = "汤瑞新111",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=9,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=10,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=11,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   },
                   new {
                       id=12,
                       timestamp = DateTime.Now,
                       author = "汤瑞新",
                        reviewer ="汤瑞新",
                        title = "测试数据！！！！！",
                        content_short="测试数据对对对",
                        content ="测试数据测试数据测试数据测试数据测试数据测试数据",
                        forecast=100.22,
                        importance = 2,
                        type = "CN",
                        status="published",
                        display_time = "2018-01-01",
                        comment_disabled = true,
                        pageviews = 2000,
                        image_uri = "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
                        platforms = new string[]{"a-platform"}
                   }
                }
            });
        }

        /// <summary>
        /// 更新作业
        /// </summary>
        /// <returns></returns>
        [HttpPost("update")]
        public IActionResult Update() => Json(new { data = "success" });

        /// <summary>
        /// 创建作业
        /// </summary>
        /// <returns></returns>
        [HttpPost("create")]
        public IActionResult  Create(){

                return Json(new { data = "success"});

        }
  
        [HttpGet("jobs")]
        public   IActionResult  Jobs(){
               var  groups = _scheduler.GetJobGroupNames(); 
            string g = ""; 
            foreach (var group in groups.Result){
                Console.WriteLine(group);
 g +=";"+ group;

            }
            return Json(new {data=g}); 
        }
    }
}
